import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:get/get.dart';
import 'package:my_app/common/ui/AppTheme.dart';
import 'package:my_app/common/ui/ui_adapter.dart';
import 'package:my_app/widget/delegate/StickyTabBarDelegate.dart';

import 'HomeController.dart';

class HomePage extends GetView<HomeController> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.white,
      body: Container(
        padding: EdgeInsets.only(top: MediaQuery.of(context).padding.top),
        child: DefaultTabController(
          length: 2,
          child: NestedScrollView(
            headerSliverBuilder: (BuildContext context, bool innerBoxIsScrolled) {
              return <Widget>[
                _buildHear(),
                SliverAppBar(
                  primary: false,
                  pinned: true,
                  title: TabBar(
                    indicatorColor: AppTheme.selectColor,
                    labelColor: AppTheme.selectColor,
                    indicatorWeight: 3.0,
                    labelStyle: TextStyle(fontWeight: FontWeight.w700, fontSize: getSp(15)),
                    unselectedLabelColor: AppTheme.defColor,
                    unselectedLabelStyle: TextStyle(fontSize: getSp(14)),
                    tabs: controller.tabs,
                  ),
                )
                // SliverPersistentHeader(
                //   pinned: true,
                //   delegate: StickyTabBarDelegate(
                //       child: ),
                // ),
              ];
            },
            body: TabBarView(
              children: controller.tabBarView,
            ),
          ),
        ),
      ),
    );
  }

  _buildHear() {
    return SliverAppBar(
      primary: false,
      leading: Container(
        child: IconButton(
          padding: EdgeInsets.only(left: getWidth(5)),
          icon: CircleAvatar(
            radius: 20,
            backgroundImage: NetworkImage("https://qlib-1253703184.cos.ap-guangzhou.myqcloud.com/20211/d8a7ffc9ba052300efb3e013c04b3578.jpeg"),
          ),
        ),
      ),
      title: Container(
        height: getHeight(30),
        width: getWidth(200),
        child: Row(
          children: [
            Padding(
              padding: EdgeInsets.only(left: getWidth(10)),
              child: Icon(Icons.search_sharp, color: Colors.grey),
            )
          ],
        ),
        decoration: BoxDecoration(borderRadius: BorderRadius.circular(30), color: Colors.grey.withAlpha(32)),
      ),
      actions: [
        IconButton(
          // padding: EdgeInsets.only(right: getWidth(1)),
          icon: Icon(Icons.games),
        ),
        IconButton(
          padding: EdgeInsets.only(right: getWidth(10)),
          icon: Icon(Icons.email_outlined),
        )
      ],
    );
  }
}
